package com.dyz.leetcode._19_greedy;

import java.util.Arrays;
import java.util.Comparator;

public class _1029_twoCitySchedCost {
    public int twoCitySchedCost(int[][] costs) {
        Arrays.sort(costs, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return (o1[0]-o1[1])-(o2[0]-o2[1]);
            }
        });

        int n = costs.length/2;
        int total = 0;
        for(int i = 0; i<n; i++){
            total+=costs[i][0]+costs[i+n][1];
        }
        return total;
    }
}
